package com.joelbitar.switchctrl;

import java.util.ArrayList;

import android.content.Context;
import android.util.Log;

public class Preference {
	public static final int TYPE_INT = 1;
	public static final int TYPE_BOOL = 2;
	public static final int TYPE_STRING = 3;
	
	private Context context;
	
	private String key;
	private int type = 0;
	private int id;
	private String name;
	private String desc;
	private int resourceId;
	
	private int spinner_names_resource;
	private ArrayList<?> spinner_values;
	
	private Object value = null;
	private Object defaultValue;
	private int value_int;
	private String value_string;
	private boolean value_bool;
	
	public Preference(Context context) {
		this.context = context;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getName() {
		return name;
	}
	public void setType(int type) {
		this.type = type;
	}
	public int getType() {
		return type;
	}
	/**
	 * @param key the key to set
	 */
	public void setKey(String key) {
		this.key = key;
	}
	/**
	 * @return the key
	 */
	public String getKey() {
		return key;
	}
	/**
	 * @param desc the desc to set
	 */
	public void setDesc(String desc) {
		this.desc = desc;
	}
	/**
	 * @return the desc
	 */
	public String getDesc() {
		return desc;
	}
	/**
	 * @param spinner_values the spinner_values to set
	 */
	public void setSpinnerValues(ArrayList<?> spinner_values) {
		this.spinner_values = spinner_values;
	}
	/**
	 * @return the spinner_values
	 */
	public ArrayList<?> getSpinnerValues() {
		return spinner_values;
	}
	/**
	 * @param spinner_names_resource the spinner_names_resource to set
	 */
	public void setSpinnerNamesResource(int spinner_names_resource) {
		this.spinner_names_resource = spinner_names_resource;
	}
	/**
	 * @return the spinner_names_resource
	 */
	public int getSpinnerNamesResource() {
		return spinner_names_resource;
	}
	/**
	 * @param resourceId the resourceId to set
	 */
	public void setResourceId(int resourceId) {
		this.resourceId = resourceId;
	}
	/**
	 * @return the resourceId
	 */
	public int getResourceId() {
		return resourceId;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}
	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}
	/**
	 * @param value the value to set
	 */
	public void setValue(Object value) {
		this.value = value;
	}
	/**
	 * @return the value
	 */
	public Object getValue() {
		if(this.value == null)
		{
			Log.i("getvalue", "value is Null, returning the default value");
			return this.defaultValue;
		}
		else
		{
			return this.value;
		}
	}
	
	/**
	 * @param defaultValue the defaultValue to set
	 */
	public void setDefault(Object defaultValue) {
		this.defaultValue = defaultValue;
	}
	/**
	 * @return the defaultValue
	 */
	public Object getDefault() {
		return defaultValue;
	}
	
	public Object getStoredValue()
	{
		Preferences prefs = new Preferences(this.context);
		return prefs.getValue(this);
	}
	
	public boolean getStoredValueBoolean()
	{
		if((Integer) this.getStoredValue() == 1)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	public int getIndexOfStoredValue() {
		// TODO Auto-generated method stub
		return this.getSpinnerValues().indexOf(this.getStoredValue());
	}
}
